//
//  ZHJNetWorkHelper.h
//  NetWorking
//
//  Created by 红军张 on 2018/7/11.
//  Copyright © 2018年 红军张. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "ZHJRequestConfig.h"

#define WS(weakSelf) __weak __typeof(&*self)weakSelf = self;
#define ValidationIdentityURL @"https://cloudapi.linkface.cn/identity/liveness_idnumber_verification"
#define IdentitySDK_Version @"identitySDK_0.05_180709_R"

/**上传文件成功之后的回调 */
typedef void(^UploadMyFileSuccess)(id dataResource);

/** 上传或者下载的进度, Progress.completedUnitCount:当前大小 - Progress.totalUnitCount:总大小*/
typedef void (^HttpProgress)(NSProgress *progress);

@interface ZHJNetWorkHelper : NSObject

/**
 *  单例
 *
 *  @return 网络请求类的实例
 */
+(instancetype _Nonnull)defaultManager;


/**
 *  设置请求头
 */
+ (void)setValue:(NSString *)value forHTTPHeaderField:(NSString *)field;

/**
 *  是否打开网络状态转圈菊花:默认打开
 *
 *  @param open YES(打开), NO(关闭)
 */
+ (void)openNetworkActivityIndicator:(BOOL)open;

/**
 取消所有请求
 */
+ (void)cancelAllRequest;

/**
 取消指定请求
 
 @param URL 地址
 */
+ (void)cancelRequestWithURL:(NSString *)URL;

/**
 常用网络请求方式
 
 @param Config 请求配置文件
 @param progress 进度
 @param success 成功
 @param failure 失败
 */
- (void)sendRequestMethod:(ZHJRequestConfig*)Config
progress:(nullable void (^)(NSProgress * _Nullable progress, NSString *tag))progress
success:(nullable void(^) (BOOL isSuccess, id _Nullable responseObject))success
failure:(nullable void(^) (NSString * _Nullable errorMessage))failure;

/**
 下载文件
 
 @param URL 下载地址
 @param fileDir 存储路径
 @param progress 下载进度
 @param success 成功
 @param failure 失败
 @return 下载任务
 */
+ (NSURLSessionTask *)downloadWithURL:(NSString *)URL
fileDir:(NSString *)fileDir
progress:(HttpProgress)progress
success:(void(^)(NSString *))success
failure:(nullable void(^) (NSString  *_Nullable error))failure;

/**
 post 表单

 @param kDetectUrl 服务器地址
 @param parameters 参数
 @param fileData 单个文件数据
 @param successBlock 成功
 @param failureBlock 失败
 */
+ (void)postMultipartFormWithUrlString:(NSString *)kDetectUrl parameters:(id)parameters data:(NSData*)fileData success:(nullable void(^) (id _Nullable responseObject))successBlock failure:(nullable void(^) (NSString * _Nullable errorMessage))failureBlock;

@end
